package com.kaiwukj.android.ufamily.mvp.ui.page.service.gm;

import android.graphics.Color;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.SizeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.GMOrderResult;
import com.kaiwukj.android.ufamily.mvp.ui.widget.FlowLayoutManager;
import com.kaiwukj.android.ufamily.mvp.ui.widget.TeamSpaceItemDecoration;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

public class GMOrderAdapter extends BaseQuickAdapter<GMOrderResult, BaseViewHolder> {
    public GMOrderAdapter() {
        super(R.layout.item_service_gm_order, new ArrayList<>());
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, GMOrderResult item) {
        QMUIRoundButton roundButton = holder.getView(R.id.btn_type);
        if (item.getProjectType() == 1) {
            roundButton.setText("新房装修");
            roundButton.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.app_color_theme));
        } else if (item.getProjectType() == 2) {
            roundButton.setText("旧房改造");
            roundButton.setBackgroundColor(Color.parseColor("#FFFDB832"));
        } else {
            roundButton.setText("其它");
            roundButton.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.app_color_theme));
        }

        holder.setText(R.id.tv_title, item.getProjectName());
        holder.setText(R.id.tv_service_start_time, String.format("开工日期:     %s", item.getStartDate()));
        holder.setText(R.id.tv_service_process, String.format("项目阶段:     %s", item.getProjectPhaseStr()));
        holder.setText(R.id.tv_location, item.getDecorationAddress());

        RecyclerView rvFlag = holder.getView(R.id.rv_tag);
        rvFlag.setLayoutManager(new FlowLayoutManager());
        if (rvFlag.getItemDecorationCount() == 0) {
            rvFlag.addItemDecoration(new TeamSpaceItemDecoration(SizeUtils.dp2px(5)));
        }
        GMOrderTagAdapter tagAdapter = new GMOrderTagAdapter(item.getTagList());
        rvFlag.setAdapter(tagAdapter);
    }
}
